package com.roc.steelend.controller;


import com.roc.steelend.controller.vo.returnformat.ReturnMsgForTable;
import com.roc.steelend.pojo.SmallType;
import com.roc.steelend.service.SmallTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.crypto.MacSpi;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin
@Api(tags = "产品小类功能接口")
public class SmallTypeController {


    @Autowired
    private SmallTypeService smallTypeService;


    @GetMapping("/v1/small-type-show")
    @ApiOperation(value = "展示产品小类",notes = "需要传入一个产品大类id,临时出现的bug,带钢大类的小类要出现在平板销售/采购界面，所以需要第二个参数可以传带钢id")
    public   List<HashMap<String, Object>> smallTypeShow(@RequestParam(value = "bigTypeId",required = true)@ApiParam(value = "产品大类Id",required = true)Integer bigTypeId,
                                                         @RequestParam(value = "bugMsg",required = false)@ApiParam(value = "bug信息",required = false)Integer bugMsg){
        List<HashMap<String, Object>> smallTypeByBigType = smallTypeService.findSmallTypeByBigType(bigTypeId);
        if (bugMsg!=null){
            List<HashMap<String, Object>> smallTypeByBigType1 = smallTypeService.findSmallTypeByBigType(bugMsg);
            ArrayList<HashMap<String, Object>> maps = new ArrayList<>(smallTypeByBigType);
            maps.addAll(smallTypeByBigType1);
            return maps;

        }else {
            return smallTypeByBigType;
        }

    }

    @GetMapping("/v1/small-type-show/reverse")
    @ApiOperation(value = "展示产品小类(其他商品)",notes = "展示除带钢，平板，卷板以外的所有大类产品")
    public   List<HashMap<String, Object>> smallTypeShowReverse(){

        return smallTypeService.findSmallTypeShowReverse();
    }

    @GetMapping("/v1/small-type-show/condition")
    @ApiOperation(value = "展示产品小类(在记录查询条件器上使用)",notes = "可以有一个产品大类Id")
    public   List<SmallType> smallTypeShowCondition(@RequestParam(value = "bigTypeId",required = false)@ApiParam(value = "产品大类Id",required = false)Integer bigTypeId){

    return smallTypeService.findSmallTypeShowCondition(bigTypeId);
    }

    @GetMapping("/v1/small-type-show/detail")
    @ApiOperation(value = "展示产品小类(在系统管理的展示页上)",notes = "可以传入一个大类id，必须传入now,size")
    public ReturnMsgForTable smallTypeShowDetail(@RequestParam(value = "now",required = true)Integer now,
            @RequestParam(value = "size",required = true)Integer size,
            @RequestParam(value = "bigTypeId",required = false)@ApiParam(value = "产品大类Id",required = false)Integer bigTypeId){

        return  smallTypeService.findSmallTypeShowDetail(now,size,bigTypeId);
    }

}
